package com.qianfeng.openplateform.search.util;

import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.json.JsonXContent;

import java.io.IOException;

/**
 * @author 江江
 * @Date 2020/7/30 10:29
 */
public class EsUtils {
    public static XContentBuilder getBuilder(){
        try {
            XContentBuilder builder = JsonXContent.contentBuilder()
                    .startObject()
                    .startObject("properties")
                    .startObject("app_key").field("type", "keyword").endObject()
                    .startObject("remoteIp").field("type", "ip").endObject()
                    .startObject("serverIp").field("type", "ip").endObject()
                    .startObject("apiName").field("type", "keyword").endObject()
                    .startObject("reveivceTime").field("type", "date").field("format", "yyyy-MM-dd HH:mm:ss").endObject()
                    .startObject("responseTime").field("type", "date").field("format", "yyyy-MM-dd HH:mm:ss").endObject()
                    .startObject("totalTime").field("type", "long").endObject()
                    .startObject("content").field("type", "text").field("analyzer", "ik_max_word").endObject()
                    .endObject()
                    .endObject();
            return builder;
        } catch (IOException e) {
            e.printStackTrace();
        }
return null;
    }
}
